<?php
namespace Admin\Controller;
use Admin\Common\BaseController;
class AboutController extends BaseController {
    public function index(){
        $about = M('about');
    	$search = I('get.search');
    	
    	if(!empty($search)){
    		$where = "name like '%".$search."%'";
    	}else{
    		$where = "";
    	}

    	$count = $about -> where($where) -> count();
    	$page = new \Think\Page($count,5);
    	$show = $page -> show();
    	$limit = $page -> firstRow.','.$page -> listRows;
    	$data = $about -> limit($limit) -> where($where) -> order('firsttime desc') -> select();
    	
    	$this -> pagestr = $show;
        $this -> assign('search',$search);
    	$this -> assign('data',$data);
        $this -> display();
    }
    //删除
    public function delete(){
        $id = (int)I('post.id');
        $about = M('about');
        $res = $about -> where('id = "'.$id.'"') -> delete();
        if($res){
            echo 1;//成功
        }else{
            echo 2;//失败
        }
    }
    //批量删除
    public function del(){
    	$about = M('about');

    	$id = I('post.id');
    	
    	//转为字符串
    	$did = implode(',',$id);
    	//in 方法
    	$where['id'] = array('in',$did);

    	$res = $about -> where($where) -> delete();
    	if($res){
    		echo "<script>
                alert('删除成功');
                window.location.href='".U('Admin/About/index')."';
            </script>";
    	}else{
    		echo "<script>
                alert('删除失败');
                window.location.href='".U('Admin/About/index')."';
            </script>";
    	}
    }
}